Skip to content

Event: Warn and fill event aliases #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

dmethvin
Copy link
Member

@dmethvin dmethvin commented Dec 5, 2016

Fixes #230

@mention-bot
Copy link

@dmethvin, thanks for your PR! By analyzing the history of the files in this pull request, we identified @markelog, @mgol and @LaurentBarbareau to be potential reviewers.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 88.189% when pulling 334cb78 on dmethvin:230-alias into 9e3dfcb on jquery:master.

@@ -199,3 +199,15 @@ See jQuery-ui [commit](https://github.com/jquery/jquery-ui/commit/c0093b599fcd58
**Cause:** The calling code has attempted to attach a `load` event to `window` after the page has already loaded. That means the handler will never run and so is probably not what the caller intended. This can occur when the event attachment is made too late, for example, in a jQuery ready handler. It can also occur when a file is loaded dynamically with jQuery after the page has loaded, for example using the `$.getScript()` method.

**Solution:** If a function `fn` does not actually depend on all page assets being fully loaded, switch to a ready handler `$( fn )` which runs earlier and will aways run `fn` even if the script that contains the code loads long after the page has fully loaded. If `fn` actually does depend on the script being fully loaded, check `document.readyState`. If the value is `"complete"` run the function immediately, otherwise use `$(window).on( "load", fn )`.

### JQMIGRATE: jQuery.fn.click() event shorthand is deprecated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not generalize this header?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to figure out the best way to do this. My concern with generalizing the header was that it wouldn't be an exact match. The most common shorthand (I think) is click so i figured this approach would yield the best results with the others in the text. Another way is to duplicate the exact messages but that would get out of hand with so many on the list now. Or I can change it to something like METHOD. What do you think?

// Handle event binding
jQuery.fn[ name ] = function( data, fn ) {
migrateWarn( "jQuery.fn." + name + "() event shorthand is deprecated" );
return arguments.length > 0 ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remember the old functions and call them instead duplicating logic in core?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? This code should work even if event shorthands are removed from Core.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as i know we don't plan to remove it. And if/when we remove it, warning should be changed regardless

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be missing if someone compiles the deprecated module out. @dmethvin does Migrate support such a scenario?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems reimplementing is more preferable, judging by the rest of the source anyway

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our approach for 3.0 has been to implement the deprecated functionality even if it's still in core. It does handle the scenario of custom builds better i guess.

@dmethvin
Copy link
Member Author

@markelog @mgol LMK if there's anything more you'd like done here.

"scroll click submit keydown".split( " " ).forEach( function( name ) {
expectWarning( "." + name + "()", 1, function() {
$div[ name ]( function( event ) {
assert.equal( event.type, name, name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A missing space before )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and a missing semi-colon at the end. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh great now I have to go figure out why the eslint settings missed that. :)

@@ -94,6 +94,37 @@ QUnit.test( ".delegate() and .undelegate()", function( assert ) {
} );
} );

QUnit.test( "Event aliases", function( assert) {
assert.expect( 16 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the 16 come from? I counted 14:

  • in the first block: 4 warnings & 4 assert.equals
  • in the second block: 1 warning & 2 assert.oks
  • in the third block: 1 warning & 2 assert.equals

What am I missing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man, you're right. It was picking up 2 extra from previously attached event handlers. Nice catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants